import collections
class Solution(object):
    def longestPalindrome(self, words):
        c = collections.Counter(words)
        ans = 0
        dan = False
        for key in c:
            if key[0] == key[1]:
                ans += (c[key] // 2) * 2
                if c[key] % 2:
                    dan = True
            else:
                if key[::-1] in c:
                    min_val = min(c[key], c[key[::-1]])
                    c[key] -= min_val
                    c[key[:: -1]] -= min_val
                    ans += 2 * min_val
        if dan:
            return 2 * (ans + 1)
        else:
            return 2 * ans